package com.aigc.sclassroom.mapper;

import com.aigc.sclassroom.pojo.Sign;
import com.aigc.sclassroom.pojo.SignRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SignMapper{
    /**
     * 检查用户是否已签到
     *
     * @param signId 签到记录的ID
     * @param userId 用户的ID
     * @return 如果用户已签到，返回1；否则返回0
     */
    @Select("SELECT COUNT(*) FROM sign_record WHERE sign_id = #{signId} AND user_id = #{userId}")
    Integer checkSigned(@Param("signId") Long signId, @Param("userId") Long userId);
    /**
     * 根据签到ID查询签到记录列表
     *
     * @param signId 签到ID
     * @return 返回一个包含签到记录的列表
     */
    @Select("SELECT * FROM sign_record WHERE sign_id = #{signId}")
    List<SignRecord> selectBySignId(@Param("signId") Long signId);

    /**
     * 插入签到记录
     *
     * @param sign 签到记录对象
     */
    @Insert("INSERT INTO sign (class_id,sign_code,start_time,end_time,duration) VALUES (#{classId},#{signCode},#{startTime},#{endTime},#{duration})")
    void insertSign(Sign sign);

    @Select("SELECT * FROM sign WHERE sign_id = #{signId}")
    Sign selectById(Long signId);


    @Select("SELECT COUNT(*) FROM sign WHERE class_id = #{classId}")
    Integer selectCountByClassId(Long classId);
}
